<script setup lang="ts">
import { getDoctorPage as getDoctorPageAPI } from '@/services/consult'
import DoctorCard from './DoctorCard.vue'
import { useWindowSize } from '@vueuse/core'
import { ref } from 'vue'
import type { DoctorList, PageParams } from '@/types/consult'
// width 直接就是当前窗口的宽度
const { width } = useWindowSize()

const params = ref<PageParams>({
  current: 1,
  pageSize: 5
})

// 关注列表
const list = ref<DoctorList>([])

const getDoctorPage = async () => {
  const r = await getDoctorPageAPI(params.value)
  list.value = r.data.rows
}

getDoctorPage()
</script>

<template>
  <div class="follow-doctor">
    <div className="head">
      <p>推荐关注 {{ width }}</p>
      <a href="javascript:;"> 查看更多<i class="van-icon van-icon-arrow" /></a>
    </div>
    <div class="body">
      <!-- swipe 组件 -->
      <!-- width 表示每次滑动 150px -->
      <!-- show-indicators 指示器 -->
      <!-- loop 无缝滚动 -->
      <van-swipe
        :width="width * (150 / 375)"
        :show-indicators="false"
        :loop="false"
      >
        <van-swipe-item v-for="item in list" :key="item.id">
          <doctor-card :item="item" />
        </van-swipe-item>
      </van-swipe>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.follow-doctor {
  background-color: var(--cp-bg);
  height: 250px;

  .head {
    display: flex;
    justify-content: space-between;
    height: 45px;
    align-items: center;
    padding: 0 15px;
    font-size: 13px;

    > a {
      color: var(--cp-tip);
    }
  }

  .body {
    width: 100%;
    overflow: hidden;
  }
}
</style>
